<?php
//array_flip for repeated array membership

function mime_multipart_related(
    $a,$sep="--xxxxxxxxxxxxxx",
    $type='txt',$multipart='',$related=false,$mixed=false,$alternative=false,
    $id=true,$content_id_tag=true,$content_id_host=true
){
    $types=array();
    $type['txt']='text/plain'; $type['text']='text/plain'; $type['text/plain']='text/plain';
    $type['xml']='text/xml'; $type['text/xml']='text/xml';
    $type['css']='text/css'; $type['text/css']='text/css';

    $msg='MIME-Version: 1.0
';
    
    /*Content-ID + Message_ID*/
    /*todo*/
    if($id===true){
        //$msg.='Content-ID: <';
    }
    if($id_tag===true)$id_host=microtime();
        if($id_host===true)
            $id_host='@aelgoa'; //get host name
        }
    }
    //$msg.=$id_tag.'@'.$id_host.'>';
    /*todo*/

    /*Content-Type*/
    if($type='multipart'){
        if($related)$multipart='related';
        if($mixed)$multipart='mixed';
        if($alternative)$multipart='alternative';
        $msg.='Content-Type: multipart/'.($multipart!=''?$multipart:'mixed').'
';
    }
    else if(in_array($type,$types))$msg.='Content-Type: '.$types[$type.'
'];
    else$msg.='Content-Type: text/plain
';

    //pffff http://en.wikipedia.org/wiki/MIME#Content-Disposition
    
    $ai; $ac=count($a);
    for($ai=0;$ai<$ac;++$ai){
        $av=$a[$ai];
        if($av==array()){
        //convert $av to an array of function calls to
        //mime(key,value)
        }
        else{
            $a[$ai]=(string)$a;
        }
    }

    if(""=="multipart"){
        if(""=="related"){
            $msg.=implode($sep,$a);
        }
    }
    return $msg;
}
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

?>
